using System.Collections;
using UnityEngine;

public class EOTDCutscene_CakeCauldron : MonoBehaviour
{
	public int CutsceneIndex;

	[SerializeField]
	private Susie_Follower Susie;

	[SerializeField]
	private GameObject Explosion;

	[SerializeField]
	private GameObject Cake;

	[SerializeField]
	private SpriteRenderer CakeRenderer;

	[SerializeField]
	private GameObject Cake_Left;

	[SerializeField]
	private GameObject Cake_Right;

	[SerializeField]
	private GameObject CakeSplat;

	[SerializeField]
	private INT_Chat CutsceneChatter;

	[SerializeField]
	private INT_Chat CauldronChatter;

	[SerializeField]
	private CHATBOXTEXT CutsceneChats;

	[SerializeField]
	private Animator SusieGlowAnimator;

	[SerializeField]
	private GameObject HealParticlePrefab;

	private GameObject storedparticle;

	[SerializeField]
	private AudioSource CutsceneSource;

	[SerializeField]
	private AudioClip[] CutsceneSounds;

	private void Start()
	{
		if (PlayerPrefs.GetInt("EOTD_CakeCutscene", 0) == 0)
		{
			PlayerPrefs.SetInt("EOTD_CakeCutscene", 1);
		}
		else
		{
			CauldronChatter.CurrentIndex = 1;
		}
	}

	private void LateUpdate()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		CakeSplat.transform.position = ((Component)PlayerManager.Instance._PAnimation).transform.position;
	}

	private void Update()
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0408: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Unknown result type (might be due to invalid IL or missing references)
		//IL_0624: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_0639: Unknown result type (might be due to invalid IL or missing references)
		//IL_0643: Unknown result type (might be due to invalid IL or missing references)
		//IL_0648: Unknown result type (might be due to invalid IL or missing references)
		//IL_0658: Unknown result type (might be due to invalid IL or missing references)
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_0687: Unknown result type (might be due to invalid IL or missing references)
		//IL_068c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0696: Unknown result type (might be due to invalid IL or missing references)
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0509: Unknown result type (might be due to invalid IL or missing references)
		//IL_050e: Unknown result type (might be due to invalid IL or missing references)
		//IL_051e: Unknown result type (might be due to invalid IL or missing references)
		//IL_053e: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0552: Unknown result type (might be due to invalid IL or missing references)
		//IL_055c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0571: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0470: Unknown result type (might be due to invalid IL or missing references)
		//IL_047f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_070f: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0723: Unknown result type (might be due to invalid IL or missing references)
		//IL_072d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0732: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
		if (CutsceneIndex != 0)
		{
			PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Cutscene;
			DarkworldMenu.Instance.CanOpenMenu = false;
		}
		switch (CutsceneIndex)
		{
		case 2:
			((MonoBehaviour)this).StartCoroutine(DelayBeforeExplosion());
			IncrementCutscene();
			break;
		case 4:
			Explosion.SetActive(true);
			Explosion.GetComponent<Animator>().Play("spr_badexplosion_explode");
			CutsceneSource.PlayOneShot(CutsceneSounds[0]);
			IncrementCutscene();
			break;
		case 5:
			Cake.SetActive(true);
			Cake.transform.position = Vector3.MoveTowards(Cake.transform.position, Explosion.transform.position + Vector3.up * 20f, 20f * Time.deltaTime);
			if (Cake.transform.position == Explosion.transform.position + Vector3.up * 20f)
			{
				Cake.transform.position = ((Component)Susie).transform.position + Vector3.up * 15f;
				IncrementCutscene();
			}
			break;
		case 6:
			Cake.transform.position = Vector3.MoveTowards(Cake.transform.position, ((Component)Susie).transform.position + Vector3.up * 2.5f, 15f * Time.deltaTime);
			if (Cake.transform.position == ((Component)Susie).transform.position + Vector3.up * 2.5f)
			{
				IncrementCutscene();
				((MonoBehaviour)this).StartCoroutine(DelayBeforeCakeSlice());
			}
			break;
		case 8:
			if (((Component)PlayerManager.Instance).transform.position.x < 0f)
			{
				Cake_Left.transform.position = Vector3.MoveTowards(Cake_Left.transform.position, ((Component)Susie).transform.position + Vector3.up * 2.5f, 15f * Time.deltaTime);
				Cake_Right.transform.position = Vector3.MoveTowards(Cake_Right.transform.position, ((Component)PlayerManager.Instance).transform.position + Vector3.up * 2.5f, 15f * Time.deltaTime);
				if (Cake_Left.transform.position == ((Component)Susie).transform.position + Vector3.up * 2.5f && Cake_Right.transform.position == ((Component)PlayerManager.Instance).transform.position + Vector3.up * 2.5f)
				{
					IncrementCutscene();
					((MonoBehaviour)this).StartCoroutine(DelayBeforeCakeSlicesDrop());
				}
			}
			else
			{
				Cake_Right.transform.position = Vector3.MoveTowards(Cake_Right.transform.position, ((Component)Susie).transform.position + Vector3.up * 2.5f, 15f * Time.deltaTime);
				Cake_Left.transform.position = Vector3.MoveTowards(Cake_Left.transform.position, ((Component)PlayerManager.Instance).transform.position + Vector3.up * 2.5f, 15f * Time.deltaTime);
				if (Cake_Right.transform.position == ((Component)Susie).transform.position + Vector3.up * 2.5f && Cake_Left.transform.position == ((Component)PlayerManager.Instance).transform.position + Vector3.up * 2.5f)
				{
					IncrementCutscene();
					((MonoBehaviour)this).StartCoroutine(DelayBeforeCakeSlicesDrop());
				}
			}
			break;
		case 9:
			if (((Component)PlayerManager.Instance).transform.position.x < 0f)
			{
				Cake_Left.transform.position = Vector3.MoveTowards(Cake_Left.transform.position, ((Component)Susie).transform.position + Vector3.up / 2f, 15f * Time.deltaTime);
				Cake_Right.transform.position = Vector3.MoveTowards(Cake_Right.transform.position, ((Component)PlayerManager.Instance).transform.position + Vector3.up / 2f, 15f * Time.deltaTime);
				CakeSplat.GetComponent<SpriteRenderer>().flipX = true;
				if (Cake_Left.transform.position == ((Component)Susie).transform.position + Vector3.up / 2f && Cake_Right.transform.position == ((Component)PlayerManager.Instance).transform.position + Vector3.up / 2f)
				{
					IncrementCutscene();
				}
			}
			else
			{
				Cake_Right.transform.position = Vector3.MoveTowards(Cake_Right.transform.position, ((Component)Susie).transform.position + Vector3.up / 2f, 15f * Time.deltaTime);
				Cake_Left.transform.position = Vector3.MoveTowards(Cake_Left.transform.position, ((Component)PlayerManager.Instance).transform.position + Vector3.up / 2f, 15f * Time.deltaTime);
				CakeSplat.GetComponent<SpriteRenderer>().flipX = false;
				if (Cake_Right.transform.position == ((Component)Susie).transform.position + Vector3.up / 2f && Cake_Left.transform.position == ((Component)PlayerManager.Instance).transform.position + Vector3.up / 2f)
				{
					IncrementCutscene();
				}
			}
			break;
		case 10:
			Cake_Left.SetActive(false);
			Cake_Right.SetActive(false);
			SusieGlowAnimator.Play("SusieGlow_Heal");
			Susie.SusieAnimator.Play("SusieDarkworld_Eat");
			storedparticle = Object.Instantiate<GameObject>(HealParticlePrefab);
			storedparticle.transform.position = ((Component)Susie).transform.position;
			CutsceneSource.PlayOneShot(CutsceneSounds[2]);
			CutsceneSource.PlayOneShot(CutsceneSounds[1]);
			CakeSplat.SetActive(true);
			((MonoBehaviour)this).StartCoroutine(DelayBeforeSusieAsk());
			IncrementCutscene();
			break;
		case 13:
			CutsceneIndex = 0;
			PlayerManager.Instance._PlayerState = PlayerManager.PlayerState.Game;
			DarkworldMenu.Instance.CanOpenMenu = true;
			break;
		case 3:
		case 7:
		case 11:
		case 12:
			break;
		}
	}

	public void IncrementCutscene()
	{
		CutsceneIndex++;
	}

	public void BeginCutscene()
	{
		CutsceneIndex = 1;
	}

	private void RunFreshChat(CHATBOXTEXT text, int index, bool ForcePosition, bool OnBottom)
	{
		CutsceneChatter.FirstTextPlayed = false;
		CutsceneChatter.CurrentIndex = index;
		CutsceneChatter.FinishedText = false;
		CutsceneChatter.Text = text;
		if (ForcePosition)
		{
			CutsceneChatter.ManualTextboxPosition = true;
			CutsceneChatter.OnBottom = OnBottom;
		}
		CutsceneChatter.RUN();
	}

	private IEnumerator DelayBeforeExplosion()
	{
		Susie = PartyMemberSystem.Instance.HasMemberInParty(PartyMemberSystem.Instance.Default_SusieDarkworld).PartyMemberFollowSettings;
		SusieGlowAnimator = ((Component)((Component)((Component)Susie).transform.Find("Glow")).transform.Find("GlowSprite")).GetComponent<Animator>();
		yield return (object)new WaitForSeconds(1f);
		IncrementCutscene();
	}

	private IEnumerator DelayBeforeCakeSlice()
	{
		Cake_Left.transform.position = Cake.transform.position;
		Cake_Right.transform.position = Cake.transform.position;
		yield return (object)new WaitForSeconds(1f);
		((Renderer)CakeRenderer).enabled = false;
		Cake_Left.SetActive(true);
		Cake_Right.SetActive(true);
		CutsceneSource.PlayOneShot(CutsceneSounds[1]);
		yield return (object)new WaitForSeconds(1f);
		IncrementCutscene();
	}

	private IEnumerator DelayBeforeCakeSlicesDrop()
	{
		yield return (object)new WaitForSeconds(0.5f);
		IncrementCutscene();
	}

	private IEnumerator DelayBeforeSusieAsk()
	{
		yield return (object)new WaitForSeconds(1.25f);
		Susie.SusieAnimator.Play("Idle");
		RunFreshChat(CutsceneChats, 0, ForcePosition: false, OnBottom: false);
	}
}
